package com.ueboot.weishop.admin.batch.jobs;


import com.ueboot.weishop.admin.batch.log.JobExecutionLogListener;
import com.ueboot.weishop.admin.batch.tasklet.SendDmsStepFirstTasklet;
import com.ueboot.weishop.admin.batch.tasklet.SendDmsStepSecondTasklet;
import com.ueboot.weishop.admin.batch.tasklet.SendDmsStepThirdTasklet;
import com.ueboot.weishop.admin.batch.tasklet.SendWxSmsStepTasklet;
import com.ueboot.weishop.entity.order.OrderIssueEntity;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.JobScope;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
import org.springframework.batch.item.ItemReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Map;

@Configuration
@EnableBatchProcessing
public class JobSendWxSmsConfiguration {

	@Autowired
	private JobBuilderFactory jobBuilderFactory;

	@Autowired
	private StepBuilderFactory stepBuilderFactory;

	@Autowired
	private SendWxSmsStepTasklet sendWxSmsStepTasklet;

	@Bean
	public ItemReader<Map<String, String>> reader() {
		return null;
	}

	//job
	@Bean
	public Job jobSendWxSms() {
		return jobBuilderFactory.get("jobSendWxSms")
				.incrementer(new RunIdIncrementer())//配置使每个job的运行id都唯一，所以即使Job执行结果是Complete也会执行
				.start(stepSendSms())
				.listener(new JobExecutionLogListener("下发DMS优惠券的数据推送模板消息")).build();
	}

	//step：更新当前时间下已支付的订单 extStatus状态为1。做好发送DMS数据准备
	@Bean
	@JobScope
	public Step stepSendSms() {
		return stepBuilderFactory.get("stepSendSms").tasklet(sendWxSmsStepTasklet).build();
	}
}
